package com.example.aircraftwar.codes.activity;

import static com.example.aircraftwar.codes.application.ImageManager.BACKGROUND_IMAGE_DIFFICULT;
import static com.example.aircraftwar.codes.application.ImageManager.BACKGROUND_IMAGE_NORMAL;
import static com.example.aircraftwar.codes.application.ImageManager.BACKGROUND_IMAGE_SIMPLE;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import com.example.aircraftwar.codes.application.ImageManager;
import com.example.aircraftwar.codes.application.game.DifficultGame;
import com.example.aircraftwar.codes.application.game.Game;
import com.example.aircraftwar.codes.application.game.NormalGame;
import com.example.aircraftwar.codes.application.game.SimpleGame;
import com.example.aircraftwar.codes.application.music.SoundService;

public class GameActivity extends Activity {
    public static int WINDOW_WIDTH;
    public static int WINDOW_HEIGHT;
    @SuppressLint("StaticFieldLeak")
    public static Game game;
    public String difficulty;
    public static SoundService.MyBinder myBinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WINDOW_WIDTH = this.getResources().getDisplayMetrics().widthPixels;
        WINDOW_HEIGHT = this.getResources().getDisplayMetrics().heightPixels;
        ImageManager.initImages(this);
        Intent intent = getIntent();
        difficulty = intent.getStringExtra("difficulty");
        boolean videoOpen = intent.getBooleanExtra("videoOpen", false);
        if (difficulty.equals("simple")) {
            game = new SimpleGame(this, BACKGROUND_IMAGE_SIMPLE, videoOpen);
        }
        if (difficulty.equals("normal")) {
            game = new NormalGame(this, BACKGROUND_IMAGE_NORMAL, videoOpen);
        }
        if (difficulty.equals("difficult")) {
            game = new DifficultGame(this, BACKGROUND_IMAGE_DIFFICULT, videoOpen);
        }
        Connect conn = new Connect();
        Intent intent_sound = new Intent(this, SoundService.class);
        intent_sound.putExtra("videoOpen",videoOpen);
        bindService(intent_sound, conn, Context.BIND_AUTO_CREATE);
        setContentView(game);
        game.action();
    }

    class Connect implements ServiceConnection {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service){
            myBinder = (SoundService.MyBinder)service;
        }
        @Override
        public void onServiceDisconnected(ComponentName componentName) {

        }
    }

}